package com.kyl.config;

import com.kyl.file.FileStorageService;
import com.kyl.properties.MinIOConfigProperties;
import io.minio.MinioClient;
import lombok.Data;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import javax.annotation.Resource;

/**
 * @author WanJl
 * @version 1.0
 * @title MinIOConfig
 * @description MinIO核心配置类
 * @create 2024/7/3
 */
@Data
@Configuration
@EnableConfigurationProperties({MinIOConfigProperties.class})
//当使用FileStorageService接口时
@ConditionalOnClass({FileStorageService.class})
public class MinIOConfig {

    @Resource
    private MinIOConfigProperties minIOConfigProperties;

    @Bean
    public MinioClient getMinioClient() {
        return MinioClient.builder()
                .credentials(minIOConfigProperties.getAccessKey(), minIOConfigProperties.getSecretKey())//用户名密码
                .endpoint(minIOConfigProperties.getEndpoint())//url
                .build();
    }
}
